<?php
namespace Modules\Wechat\Model\Data\OfficialAccount;

use Base\Exception\Data as Exception;
use S\Cache\Cache;
use S\Request;

/**
 * 正在处理的微信号
 *
 * 就是在管理后台中正在处理的微信号.
 *
 * @package Modules\Wechat\Model\Data\OfficialAccount
 */
class Handling
{

    const DEFAULT_EXPIRES          = 0;
    const DEFAULT_CACHE_KEY_PREFIX = 'admin-wechat-handling-account-';

    public static function set($account, $expires = self::DEFAULT_EXPIRES)
    {
        if (empty($account)) {
            throw new Exception('error.admin_wechat.handling_account_empty');
        }
        return Cache::set(static::getCacheKey(), $account, $expires) ? $account : '';
    }

    public static function get()
    {
        return Cache::get(static::getCacheKey()) ?: '';
    }

    public static function del()
    {
        return Cache::del(static::getCacheKey());
    }

    protected static function getCacheKey($unique = '')
    {
        return static::DEFAULT_CACHE_KEY_PREFIX . ($unique ?: Request::session('uid'));
    }
}